﻿
using NHibernate;
using NUnit.Framework;
using AdventureWorks.DataAccess.Utils;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Context;
using System;
namespace AdventureWorks.DataAccess.Test.repository
{
    [TestFixture]
    public abstract class RepositoryTestBase<T> where T : new()
    {
        protected T repository;
        protected ISession session;
        protected ITransaction transaction;

        protected static ISessionFactory SessionFactory
        {
            get { return SessionManager.SessionFactory; }
        }


        [SetUp]
        public void Setup()
        {
            session = SessionFactory.OpenSession();
            session.FlushMode = FlushMode.Always;
            repository = new T();
            transaction = session.BeginTransaction();
        }

        [TearDown]
        public void Teardown()
        {
            transaction.Rollback();
            transaction.Dispose();
            repository = default(T);
            session.Close();
            session.Dispose();
        }
    }
}
